/*
 * 
 */

package cs429_project;

import java.util.ArrayList;

/**
 * A class to determine the relevant terms from an associated
 * Wikipedia page to add to the original query.
 * @author Naomi Peterson
 */
public class QueryExpansion {

    private String expandedQuery;
    private QueryAndWiki qaw;
    private ArrayList<String> TokenizedText;
    private FreqTerm[] terms;

    /*
     * This embedded class creates an Object type that allows for
     * indexing of all the terms in the given Wikipedia text plus
     * associating numeric values with each term for the weighted
     * term frequency used in the scoring algorithm.
     */
    private class FreqTerm extends Object{
            String term;
            int score;

            protected FreqTerm(String s){
                this.term=s;
                score=0;
            }

            private void IncFreq(){
                score++;
            }

            /*
             * gives option of specifying greater increase for weighted
             * occurances.
             */
            private void IncFreq(int n){
                score=score+n;
            }

            private String getTerm(){
                return this.term;
            }

            private int getScore(){
                return this.score;
            }
    }

    /*
     * The constructor returns the tokenized version of the Wiki page text
     * stored in the qaw instance, as well as setting the local qaw variable
     * to the input qaw instance.  It also sizes the terms array to be able
     * to handle a text with no repeated words and initializes the
     * ExpandedQuery string to the original query text.
     */
    public QueryExpansion(QueryAndWiki qaw1){
        this.qaw=qaw1;
        this.TokenizedText=WikiPageHandler.tokenizeText(qaw.getWikiPageText());
        this.terms[TokenizedText.size()]=null;
        this.expandedQuery=qaw.getQueryText();
    }

    /*
     * The remaining methods are described instead of coded because I
     * could not implement them without additional resources, such as
     * an index of Wikipedia.  Although we did not think we needed to
     * index Wikipedia, I later discovered that I had misread the part
     * of our journal article related to the scoring of terms in the
     * Wikipedia article used for query expansion.
     *
     * Upon reviewing this class before submission, I also just noticed
     * that the get/set methods for the private variables, most notably
     * the ExpandedQuery String are missing.
     */

    /*
     * private void scoreTokenizedText(){}
     *
     * This method would iterate through the token list and add new terms
     * to the terms array including incrementing the score according to the
     * weight of the term based on its location in the text.  Specifically,
     * words in section titles and sections such as "Introduction" or
     * "Overview" would be given a weight of 3 (titles) and 2 (summaries)
     * compared to a weight of 1 for other occurances.  However, the
     * tokenized text does not currently preserve the necessary metadate
     * to alter the weights of different occurances.
     */

    /*
     * private String[] findTopTerms(){}
     *
     * This method would determine the top n terms in the article by score.
     * That score would consist of the product of the int value in
     * terms[token].score and the inverse term frequency of token as
     * determined from the missing Wikipedia index.  It would return an
     * array of the top n tokens/terms.
     */

    /*
     * public String expandQuery(){}
     *
     * This will run through the two private methods above and toString
     * the String[] returned.  That new string will be concatnated with the
     * original query in the ExpandedQuery variable.  The driver class can
     * then run the expanded query on the original set of indexed documents.
     * This method returns the final ExpandedQuery string.
     */

}